﻿using System;
using System.Web;

namespace ValidationFramework.Web.MVC.Extensions
{
	class ValidatedFormDisposable : IDisposable
	{
		private bool disposed;
		private readonly string validationScript;
        private readonly HttpResponseBase httpResponse;

		public ValidatedFormDisposable(HttpResponseBase httpResponse, string validationScript)
		{
			this.httpResponse = httpResponse;
			this.validationScript = validationScript;
		}

		public void Dispose()
		{
			if (!disposed)
			{
				disposed = true;
				httpResponse.Write("</form>");
				httpResponse.Write(validationScript);
			}
		}
	}
}
